﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Things.ThingsWeb
{
    /// <summary>
    /// Summary description for GetImages
    /// </summary>
    public class GetImages : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string id = context.Request.QueryString["id"];
            Guid guid = Guid.Empty;
            if (Guid.TryParse(id, out guid) == false)
            {
                guid = Guid.Empty;
            }
            string className = context.Request.QueryString["ClassName"];
            switch (className)
            {
                case Things.Common.ConstantString.ClassBuyerAccount:
                    Things.BLL.BuyerInfo biBLL = new BLL.BuyerInfo();
                    Things.Model.BuyerInfo biModel = biBLL.GetModel(id);
                    if (biModel != null)
                    {
                        context.Response.BinaryWrite(biModel.BuyerIamge);
                    }
                    break;
                case Things.Common.ConstantString.ClassGoodsList:
                    Things.BLL.GoodsPrice gpBLL = new BLL.GoodsPrice();
                    Things.Model.GoodsPrice gpModel = gpBLL.GetModel(guid);
                    if (gpModel != null)
                    {
                        Things.Model.Goods gModel = new Model.Goods();
                        Things.BLL.Goods gBLL = new BLL.Goods();
                        gModel = gBLL.GetModel(gpModel.GoodsID);
                        if (gModel != null)
                        {
                            context.Response.BinaryWrite(gModel.GoodsImage);
                        }
                    }
                    break;
                case Things.Common.ConstantString.ClassOrderPlan:                    
                        Things.BLL.Goods goodsBLL = new BLL.Goods();
                        Things.Model.Goods goodsModel = goodsBLL.GetModel(guid);
                        if (goodsModel != null)
                        {
                            context.Response.BinaryWrite(goodsModel.GoodsImage);
                        }

                        break;
                case Things.Common.ConstantString.ClassCropsPlantProgressInfo:
                    Things.BLL.CropsPlantProgressInfo cppiBLL = new BLL.CropsPlantProgressInfo();
                    Things.Model.CropsPlantProgressInfo cppi = cppiBLL.GetModel(guid);
                    if (cppi != null)
                    {
                        context.Response.BinaryWrite(cppi.Image);
                    }
                    break;
                case Things.Common.ConstantString.ClassCropsProductProgressInfo:
                    Things.BLL.CropsProductProgressInfo cppiBLL1 = new BLL.CropsProductProgressInfo();
                    Things.Model.CropsProductProgressInfo cppi1 = cppiBLL1.GetModel(guid);
                    if (cppi1 != null)
                    {
                        context.Response.BinaryWrite(cppi1.Image);
                    }

                    break;
                default:
                    break;
            }


        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}